<?php
/**
 * Created by PhpStorm.
 * User: chniccs
 * Date: 2019-11-28
 * Time: 10:34
 */

namespace app\model;

//砍价规则表
use think\facade\Cache;

class AdminKanjiaRule extends Base
{

    public static function toSave($data)
    {
        $done = false;
        $data['rule'] = json_encode($data['rule']);
        if (isset($data['id'])) {
            $model = self::get($data['id']);
            if ($model) {
                $model->setAttr('rule', $data['rule']);
                $done = $model->allowField(true)->save();
            }
        } else {
            $done = self::create($data);
        }
        return $done ? true : false;
    }
}